﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;


namespace MaxStudio.Concrete.Server.Service
{
    public class RPTGravelInspectionService : ServiceHandle, IRPTGravelInspection 
    {
        #region IRPTGravelInspection Members

        public OperationResult<List<tb_RPT_GravelInspection>> GetAllGravelInspection()
        {
            OperationResult<List<tb_RPT_GravelInspection>> result = new OperationResult<List<tb_RPT_GravelInspection>>();
            List<tb_RPT_GravelInspection> list = new List<tb_RPT_GravelInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllGravelInspection();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_GravelInspection>> GetGravelInspectionByContition(string strSequence, string strProjectName, string strMaterialOrigin, string strTestDate)
        {
            OperationResult<List<tb_RPT_GravelInspection>> result = new OperationResult<List<tb_RPT_GravelInspection>>();
            List<tb_RPT_GravelInspection> list = new List<tb_RPT_GravelInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetGravelInspectionByContition(strSequence, strProjectName, strMaterialOrigin, strTestDate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_GravelInspection>> GetGravelInspectionByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_GravelInspection>> result = new OperationResult<List<tb_RPT_GravelInspection>>();
            List<tb_RPT_GravelInspection> list = new List<tb_RPT_GravelInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetGravelInspectionByProjectName(   strProjectName );
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_GravelInspection> GetGravelInspectionById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_GravelInspection> result = new OperationResult<tb_RPT_GravelInspection>();
            tb_RPT_GravelInspection gravelInspection;
            try
            {
                gravelInspection = dataContext.GetGravelInspectionById(id);
                if (gravelInspection == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = gravelInspection;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_GravelInspection> CreateGravelInspection(tb_RPT_GravelInspection entity)
        {
            OperationResult<tb_RPT_GravelInspection> result = new OperationResult<tb_RPT_GravelInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateGravelInspection(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_GravelInspection> ModifyGravelInspection(tb_RPT_GravelInspection entity)
        {
            OperationResult<tb_RPT_GravelInspection> result = new OperationResult<tb_RPT_GravelInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyGravelInspection(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_GravelInspection> DeleteGravelInspection(tb_RPT_GravelInspection entity)
        {
            OperationResult<tb_RPT_GravelInspection> result = new OperationResult<tb_RPT_GravelInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteGravelInspection(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
